//
//  DateConversion.m
//  安好
//
//  Created by rlp on 14-12-18.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "DateConversion.h"

@implementation DateConversion
+(NSString *)dataWithSecondToNow:(NSString *)second1970{
NSString *timeStr = @"";

    NSDate *nowDate = [NSDate date];
    int seconds = nowDate.timeIntervalSince1970 - [second1970 longLongValue];
    
    if(seconds < 60) {
        timeStr = @"刚刚";
    } else if(seconds < 60*60) {
        timeStr = [NSString stringWithFormat:@"%d分钟前", seconds/60%60];
    } else if(seconds < 24*60*60) {
        timeStr = [NSString stringWithFormat:@"%d小时前", seconds/60/60%24];
    } else if(seconds < 4*24*60*60) {
        timeStr = [NSString stringWithFormat:@"%d天前", seconds/60/60/24%4];
    } else {
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        [formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
        NSString *dateString = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[second1970 longLongValue]]];
        
        timeStr = dateString;
    }
    return timeStr;
}
@end
